package Lekcja_4.tablice;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import javax.swing.JLabel;
import javax.swing.JCheckBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class SixpackGUI extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SixpackGUI frame = new SixpackGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SixpackGUI() {
		final Sixpack sp = new Sixpack();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 270, 200);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		final JCheckBox chckbxPiwo = new JCheckBox("Piwo 1");
		chckbxPiwo.setEnabled(false);
		chckbxPiwo.setSelected(true);
		chckbxPiwo.setBounds(6, 7, 97, 23);
		contentPane.add(chckbxPiwo);
		
		final JCheckBox chckbxPiwo_1 = new JCheckBox("Piwo 2");
		chckbxPiwo_1.setEnabled(false);
		chckbxPiwo_1.setSelected(true);
		chckbxPiwo_1.setBounds(6, 33, 97, 23);
		contentPane.add(chckbxPiwo_1);
		
		final JCheckBox chckbxPiwo_2 = new JCheckBox("Piwo 3");
		chckbxPiwo_2.setEnabled(false);
		chckbxPiwo_2.setSelected(true);
		chckbxPiwo_2.setBounds(6, 59, 97, 23);
		contentPane.add(chckbxPiwo_2);
		
		final JCheckBox chckbxPiwo_3 = new JCheckBox("Piwo 4");
		chckbxPiwo_3.setEnabled(false);
		chckbxPiwo_3.setSelected(true);
		chckbxPiwo_3.setBounds(6, 85, 97, 23);
		contentPane.add(chckbxPiwo_3);
		
		final JCheckBox chckbxPiwo_4 = new JCheckBox("Piwo 5");
		chckbxPiwo_4.setEnabled(false);
		chckbxPiwo_4.setSelected(true);
		chckbxPiwo_4.setBounds(6, 111, 97, 23);
		contentPane.add(chckbxPiwo_4);
		
		final JCheckBox chckbxPiwo_5 = new JCheckBox("Piwo 6");
		chckbxPiwo_5.setEnabled(false);
		chckbxPiwo_5.setSelected(true);
		chckbxPiwo_5.setBounds(6, 137, 97, 23);
		contentPane.add(chckbxPiwo_5);
		
		JButton btnUkradnijPiwo = new JButton("Ukradnij piwo");
		btnUkradnijPiwo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				sp.wezPiwo();
				if(sp.ile()==5){
					chckbxPiwo.setSelected(false);
				} else if(sp.ile()==4) {
					chckbxPiwo_1.setSelected(false);
				} else if(sp.ile()==3) {
					chckbxPiwo_2.setSelected(false);
				} else if(sp.ile()==2) {
					chckbxPiwo_3.setSelected(false);
				} else if(sp.ile()==1) {
					chckbxPiwo_4.setSelected(false);
				} else {
					chckbxPiwo_5.setSelected(false);
				}
			}
		});
		btnUkradnijPiwo.setBounds(109, 0, 138, 160);
		contentPane.add(btnUkradnijPiwo);
	}
}
